#include "toolsstring.h"

void getString_ToolsString(char **message)
{
  char tmp[128];
  char *tmp2 = NULL;
  char *tmp3 = NULL;
  char continu = 1;

  do
    {
      tmp3 = fgets(tmp, 127, stdin);
      if(tmp3 != NULL)
	{
	  char * lf = strchr(tmp, '\n');
	  if (lf != NULL)
	    {
	      *lf = '\0';
	      continu = 0;
	    }

	    if(tmp2 != NULL)
		{
		  tmp3 = (char *) malloc((1 + strlen(tmp) + strlen(tmp2))
					 *sizeof(char));
		  tmp3 = strncpy(tmp3, tmp2, strlen(tmp2) + 1);
		  tmp3 = strcat(tmp3, tmp);
		  free(tmp2);
		  tmp2 = tmp3;
		  tmp3 = NULL;
		}
	      else
		{
		  tmp2 = (char *) malloc((1+strlen(tmp))*sizeof(char));
		  tmp2 = strncpy(tmp2, tmp, 1+strlen(tmp));
		}

	}
    }while(continu == 1);
  (*message) = tmp2;
}

void setStringVar_ToolsString(char **var, const char *string)
{
  if(string == NULL)
    return;
  (*var) = (char *) malloc ((strlen(string) + 1) * sizeof(char));
  if((*var) == NULL)
    {
      fprintf(stderr, "[setStringVar_ToolsString]Erreur malloc plus d'espace disponible\n");
      exit(1);
    }
  strcpy((*var), string);
}
